home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / pdisk.zip / PFORMAT.C < prev    next >
C/C++ Source or Header  |  1989-01-12  |  3KB  |  84 lines

  1. /* Program to "reformat" partitions on a fixed disk.
  2.  * Written by Scott E. Garfinkle, Sep 1986.  All rights reserved.
  3.  *
  4.  * This program will perform a "soft" reformat of a hard disk partition.
  5.  * Note that this will only block out any sectors that cannot be read.  It
  6.  * does not attempt to fix them.
  7.  *
  8.  * Requires the following external .obj files: rdioctl, rdpart, part1, misc, init
  9.  *
  10.  * usage: pformat <d:>
  11.  */
  12. #include "part.h"
  13. #include <dos.h>
  14. #include <errno.h>
  15. #include <ctype.h>
  16.  
  17. static char *buf;
  18. word partno;
  19. extern byte fixed_disk;    /* BIOS "address" of currently selected fixed disk */
  20. word sector_size;    /* aka bytes per sector */
  21. word lineno;    /* current screen line */
  22.  
  23. extern    int read_ioctl(char *buffer, word drive);
  24.  
  25. main(argc, argv)
  26. int argc;
  27. char **argv;
  28. {
  29.     word i, csize, fat_size, temp;
  30.     BPB *bptr, *pbptr;
  31.     extern BOOT part_boot_rec[4];    /* boot record of each (active) logical partition */
  32.  
  33.     if(argc != 2) {
  34.         fprintf(stderr,"Usage: pformat <drive:>\n");
  35.         exit(1);
  36.         /* NOTREACHED */
  37.     }
  38.     if((i = tolower(argv[1][0]) - 'a' + 1) < 4) {
  39.         fprintf(stderr,"pformat: must use DOS format to format dos drives.\n");
  40.         exit(2);
  41.         /* NOTREACHED */
  42.     }
  43.     erase_eos(14);
  44.     scr_pos(22,0);
  45.     printf("Partition Reformatter, Copyright(C) 1986, 1988 S. E. Garfinkle.");
  46.     scr_pos(23,0);
  47.     printf("All rights reserved.");
  48.     do {
  49.         sector_size = get_scr_val(14,"Enter sector size (256,512,1024,etc.):",512,256,16*1024);
  50.     } while (sector_size != 256 && (sector_size & 0x1ff));
  51.     erase_eos(14);
  52.     buf = malloc(sector_size);
  53.     if((i=read_ioctl(buf, i)) < 0) {
  54.         fprintf(stderr,"Illegal %s\n", i == -1 ? "ioctl function" :
  55.                                                  "Drive code");
  56.         exit(2);
  57.     }
  58.     erase_eos(20);
  59.     printf("If you proceed, you will completely erase drive %c.\n",argv[1][0]);
  60.     i = get_scr_char(21,"Are you SURE you want to continue? (y/n)",'N','y');
  61.     if(tolower(i) != 'y') {
  62.         exit(3);
  63.         /* NOTREACHED */
  64.     }
  65.     puts("\nReformatting...standby.");
  66.     partno = *(word *)(buf+sizeof(BPB)+4);
  67.     fixed_disk = partno >> 4 ? DISK1 : DISK0;
  68.     init();
  69.     partno &= 0xf;
  70.     i = make_rdir(partno);    /* returns number of sectors in root dir */
  71.     if(!i || !make_fat(partno, ((BPB *)buf)->secs_in_fat, i)) {
  72.         if(errno == ENOMEM) {
  73.             puts("Not enough memory.");
  74.         }
  75.         else {
  76.             puts("Error in creating FAT or root directory for partition.");
  77.         }
  78.         sleep(1000L);
  79.     }
  80.     erase_eos(0);
  81.     scr_pos(10,0);
  82.     printf("Drive %c is reformatted.  You should now reboot.\n",argv[1][0]);
  83. }
  84.